package org.karelun.gef.model;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Karelun huang
 * 
 */
public class DiagramModel extends Element {
	
	private static final long serialVersionUID = 3257847701181051954L;
	
	public static String PROP_NODE = "NODE"; //$NON-NLS-1$
	
	public static String PROP_CONN="CONNECTION"; //$NON-NLS-1$

	private List<Node> nodes =new ArrayList<Node>();
	
	private List<AbstractConnectionModel> connections=new ArrayList<AbstractConnectionModel>();

	public DiagramModel(){
		super();
	}
	
	public void addConnection(AbstractConnectionModel conn){
		if(connections.contains(conn))
			return;
		connections.add(conn);
		firePropertyChange(PROP_CONN, null,connections);
	}
	
	public void removeConnection(AbstractConnectionModel conn){
		if(!connections.contains(conn))
			return;
		connections.remove(conn);
		firePropertyChange(PROP_CONN,null, connections);
	}
	
	public void addNode(Node node) {
		if(nodes.contains(node))
			return;
		nodes.add(node);
		firePropertyChange(PROP_NODE,null, nodes);
	}

	public void removeNode(Node node) {
		if(!nodes.contains(node))
			return;
		nodes.remove(node);
		firePropertyChange(PROP_NODE,null, nodes);
	}

	public List<Node> getNodes() {
		return nodes;
	}
	
	public List<AbstractConnectionModel> getConnections(){
		return connections;
	}
	
	public void setNodes(List<Node> nodes) {
		this.nodes = nodes;
	}
}